import buildBarCode from '../../utils/barCode/index';
//获取应用实例
var app = getApp();
Page({
    data: {
        //处理订单
        orderStatusDoingText:"处理订单",
        orderStatusFinishText:"订单完成",
        orderStatusClass: "icon_end",
        orderStatusAdd: "icon_doing",
        orderStatusToAdd: "icon_end",
        orderStatusTextClass: "",
        orderStatusExplainClass: "icon_order_succeed",
        orderStatusLineColour: "",
        "isShowFootNav": false,
		statusName: "",
		statusDescDetail: "",
		orderTitle: "",
		totalServiceAmount: "",
		orderAmount: "",
		eOrderAddress: "",
		processTitle: "",
		orderId: "",
		isShowPage: true  //显示页面
	},

	requestData(orderId){
		let that = this;
        let opt = {
            url: app.globalData.host+"/wx/di/detail.ajax",
            data: {
                'orderId': orderId  //'201712261120590980'  // 
            },
            sucFn:(result)=> {
				let res = result.body;
				buildBarCode('barCode', res.payNbr, 600, 180);
                that.setData({
					payTypeText:  res.payType==0?'提交订单':'支付订单',
					cardName: res.cardName,
					carTypeName: res.carTypeName,
					carNbr: res.carNbr,
					payNbr: res.payNbr,
					handleTypeName: res.handleTypeName,
					carOfficeName: res.carOfficeName,

					contactName: res.address.contactName,
					cellNum: res.address.cellNum,
					address: res.address.fullAddr,
					serviceFee: res.serviceFee/100,

	                orderStatusExplainTextClass_f: res.status==3|| res.status==4|| res.status==5?'font-color-red':'',
	                orderStatusExplainClass: res.status==3|| res.status==4|| res.status==5?'icon_oeder_close_off':'icon_order_succeed',
					isShowPage: true,
					statusName: res.statusName,
					statusDescDetail: res.statusDescDetail,
	                processTitle: res.processlist[0].name,
					processTime: app.toYMDHMSDate(res.processlist[0].createTime),

	                orderId: orderId,
	                createTime: app.toYMDHMSDate(res.createTime),
					payTime: app.toYMDHMSDate(res.payTime),
					isShowPayNo: res.payNo?true:false,
					payNo: res.payNo,
					payTypeState: res.payType==0?false:true,
					payType: res.payType==0?'线下到付':res.payType==2?'支付宝':res.payType==3?'微信':'',
	                completeText: res.status==4?'关闭时间':res.status==8?'完成时间':'',
	                completeTime: app.toYMDHMSDate(res.completeTime),
	                completeTimeIsShow: res.completeTime?true:false

                });
                switch (res.status) {   //res.status
	                /*
	                 * style.icon_success      成功绿色大圆
	                 * style.icon_error        失败红色大圆
	                 * style.icon_moren_error  失败红色中圆
	                 * style.icon_moren        默认灰色中圆
	                 *
	                 * bg-color_blue 蓝色背景
	                 * bg-color_red  红色背景
	                 * */
	                case 0:
		                that.setData({
			                orderStatusTwoText:"处理订单",
			                orderStatusThreeText:"订单完成",

			                orderStatusOne: "icon_doing",
			                orderStatusTwo: "",
			                orderStatusThree: "",
			                orderSideOneLineColour: "",
			                orderSideTwoLineColour: "",
			                orderSideThreeLineColour: "",

			                orderStatusTwoTextColour: "",
			                orderStatusThreeTextColour: ""

		                });
		                break;

					case 1:
						that.setData({
			                orderStatusTwoText:"处理订单",
			                orderStatusThreeText:"订单完成",

			                orderStatusOne: "bg-color-blue",
			                orderStatusTwo: "icon_doing",
			                orderStatusThree: "",

			                orderSideOneLineColour: "bg-color-blue",
			                orderSideTwoLineColour: "bg-color-blue",
			                orderSideThreeLineColour: "",

			                orderStatusTwoTextColour: "font-color-blue",
			                orderStatusThreeTextColour: ""

		                });
		                break;

	                case 2:
						that.setData({
			                orderStatusTwoText:"处理订单",
			                orderStatusThreeText:"订单完成",

			                orderStatusOne: "bg-color-blue",
			                orderStatusTwo: "icon_doing",
			                orderStatusThree: "",

			                orderSideOneLineColour: "bg-color-blue",
			                orderSideTwoLineColour: "bg-color-blue",
			                orderSideThreeLineColour: "",

			                orderStatusTwoTextColour: "font-color-blue",
			                orderStatusThreeTextColour: ""

		                });
		                break;
	                case 3:
						that.setData({
			                orderStatusTwoText:"办理失败",
			                orderStatusThreeText:"订单完成",

			                orderStatusOne: "bg-color-blue",
			                orderStatusTwo: "icon_fail",
			                orderStatusThree: "",

			                orderSideOneLineColour: "bg-color-red",
			                orderSideTwoLineColour: "bg-color-red",
			                orderSideThreeLineColour: "",

			                orderStatusTwoTextColour: "font-color-red",
			                orderStatusThreeTextColour: ""

		                });
		                break;
	                case 4:
						that.setData({
			                orderStatusTwoText:"办理失败",
			                orderStatusThreeText:"订单关闭",

			                orderStatusOne: "bg-color-blue",  //成功大圆
			                orderStatusTwo: "icon_failed", //失败中圆
			                orderStatusThree: "icon_fail",  //失败的大圆

			                orderSideOneLineColour: "bg-color-blue",
			                orderSideTwoLineColour: "bg-color-blue",
			                orderSideThreeLineColour: "bg-color-red",

			                orderStatusTwoTextColour: "font-color-red",
			                orderStatusThreeTextColour: "font-color-red"

		                });
		                break;

	                case 5:
						that.setData({
			                orderStatusTwoText:"办理失败",
			                orderStatusThreeText:"订单已失效",

			                orderStatusOne: "bg-color-blue",  //成功大圆
			                orderStatusTwo: "icon_failed", //失败中圆
			                orderStatusThree: "icon_fail",  //失败的大圆

			                orderSideOneLineColour: "bg-color-blue",
			                orderSideTwoLineColour: "bg-color-blue",
			                orderSideThreeLineColour: "bg-color-red",

			                orderStatusTwoTextColour: "font-color-red",
			                orderStatusThreeTextColour: "font-color-red"

		                });
		                break;
	                case 8:
						that.setData({
			                orderStatusTwoText:"处理订单",
			                orderStatusThreeText:"订单完成",

			                orderStatusOne: "bg-color-blue",  
			                orderStatusTwo: "bg-color-blue", 
			                orderStatusThree: "icon_doing",  //失败的大圆

			                orderSideOneLineColour: "bg-color-blue",
			                orderSideTwoLineColour: "bg-color-blue",
			                orderSideThreeLineColour: "bg-color-blue",

			                orderStatusTwoTextColour: "font-color-blue",
			                orderStatusThreeTextColour: "font-color-blue"

		                });
		                break;

                }
            }
        };
        app.ajax(opt);
	},


    onLoad(option) {
		let orderId = option.orderId;
		this.requestData(orderId)
    },
    onHide() {
        // app.removeStorageSync(app.globalData.globalData);
    },

	toUrl() {
		app.setStorageSync(app.globalData.passCache,this.data.data)
		app.navigateTo({url:'../passInformation/passInformation?type='+'enCode'})
	},

    progressTap(e) {
        let orderId = e.target.dataset.id;
        app.navigateTo({
            url: '../travelProgress/travelProgress?orderId='+orderId
        });
    }
});
